package cn.itcast.user.web;

import cn.itcast.user.config.TimeFormatProperties;
import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RequestMapping("/user")
//@RefreshScope
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {
        return userService.queryById(id);
    }

//    dataFormat:
//  parttern
//    @Value("${dataFormat.parttern}")
//    private String dataFormatParttern;


    @Autowired
    private TimeFormatProperties timeFormatProperties;


    @Value("${common.config.devGroup}")
    private String devGroup;
    @Value("${config.active.share.priority}")
    private String configPriority;

    @GetMapping("/time/format")
    public String format(@RequestHeader String Truth) {
//        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dataFormatParttern));
        return Truth + "  " +  devGroup + "  " + configPriority + "  " + LocalDateTime.now().format(DateTimeFormatter.ofPattern(timeFormatProperties.getFormatParttern()));
    }

}
